package br.com.vti.sisp_sicrim.model.entity;

import br.com.crud4j.core.model.Model;
import br.com.crud4j.core.model.annotation.Constraint;
import br.com.crud4j.core.model.annotation.Constraints;
import br.com.vti.sisp_sicrim.model.entity.enums.Status;

import java.util.List;

import javax.persistence.Basic;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.ForeignKey;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import javax.xml.bind.annotation.XmlTransient;

/**
 *
 * @author ednardomatos
 */
@Entity
@Table(name = "t_delegacia", catalog = "desenvolvimento", schema = "e_sisp_sicrim")
@SequenceGenerator(name = "seq_delegacia", sequenceName = "e_sisp_sicrim.seq_delegacia", initialValue = 1, allocationSize = 1)
public class Delegacia implements Model<Integer> {
    
    private static final long serialVersionUID = -647957418587546414L;

    @Id
    @Basic(optional = false)
    @GeneratedValue(strategy = GenerationType.AUTO, generator = "seq_delegacia")
    private Integer id;
    
    @NotNull
    @Basic(optional = false)
    @Size(min = 1, max = 80)
    private String nome;
    
    @Size(max = 100)
    @Column(name = "nm_delegado_resp")
    private String nmDelegadoResp;
    
    @NotNull
    @Basic(optional = false)
    @ManyToOne
    @JoinColumn(name="municipio", referencedColumnName="id", foreignKey = @ForeignKey(name = "delegacia_municipio_fk"))
    private Municipio municipio;
    
    @Column(columnDefinition="bpchar(1) default 'A'")
    private Status status;
    
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "delegacia")
    private List<Incidencia> incidenciaList;

    public Delegacia() {
    }

    public Delegacia(Integer id) {
        this.id = id;
    }

    public Delegacia(Integer id, String nome, Municipio municipio) {
        this.id = id;
        this.nome = nome;
        this.municipio = municipio;
    }

    @Override
    public Integer getId() {
        return id;
    }

    @Override
    public void setId(Integer id) {
        this.id = id;
    }

    public String getNome() {
        return nome;
    }

    public void setNome(String nome) {
        this.nome = nome;
    }

    public String getNmDelegadoResp() {
        return nmDelegadoResp;
    }

    public void setNmDelegadoResp(String nmDelegadoResp) {
        this.nmDelegadoResp = nmDelegadoResp;
    }

    public Municipio getMunicipio() {
		return municipio;
	}

	public void setMunicipio(Municipio municipio) {
		this.municipio = municipio;
	}

	public Status getStatus() {
		return status;
	}

	public void setStatus(Status status) {
		this.status = status;
	}

	@XmlTransient
    public List<Incidencia> getIncidenciaList() {
        return incidenciaList;
    }

    public void setIncidenciaList(List<Incidencia> incidenciaList) {
        this.incidenciaList = incidenciaList;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (id != null ? id.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Delegacia)) {
            return false;
        }
        Delegacia other = (Delegacia) object;
        if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "Delegacia[ id=" + id + " ]";
    }
    
}
